// -*- C++ -*-
// $Id: timer.h,v 1.4 2008-05-09 13:58:51 biocomp Exp $
/*  Timer class for benchmarking and more.

    @version 0.1
    @author  Matthias Heiler */

#ifndef __TIMER
#define __TIMER

extern "C" {
#include <time.h>
}

#include <iostream>
using namespace std;

/** Timer provides an interface for timing.

    @version 0.1
    @author  Matthias Heiler */
class Timer {
public:
  Timer() : startTime(0), endTime(0) {}

  // We use default destructor and copy-constructor.

  // Modifiers.
  inline void start() { time(&startTime); }
  inline void stop() { time(&endTime); }
  inline void reset() { startTime = endTime = 0; }

  // Selectors.
  int seconds() const;
  int minutes() const;
  int hours() const;

protected:
  time_t startTime, endTime;  
};  

// output operator
inline ostream& operator<<(ostream& os, const Timer& time) {
  os << time.hours() << " hours " << (time.minutes()%60) << " minutes " 
     << (time.seconds()%60) << " seconds.";
  return os;
}

#endif
